package com.dst.smart.dao.impl.factory;

import java.util.ArrayList;
import java.util.List;


import com.dst.smart.app.MyApplication;
import com.dst.smart.model.CusDevice;

public class CusDeviceFactory {
	public static List<CusDevice> list = new ArrayList<CusDevice>();

	static {
		if (list.size() == 0) {
			list = MyApplication.getInstance().getWidgetDataBase()
					.getCusDevices();
		}
	}

	public static List<CusDevice> getAll() {
		if (list.size() == 0) {
			list = MyApplication.getInstance().getWidgetDataBase().getCusDevices();
		}
		return list;
	}

	public static String getCount() {
		if (list.size() == 0) {
			list = MyApplication.getInstance().getWidgetDataBase().getCusDevices();
		}
		return list.size() + "/" + list.size();
	}



	public static void delete(int id) {
		if (list.size() > 0) {
			for (CusDevice device : list) {
				if (device.getId() == id) {
					list.remove(device);
					break;
				}
			}
		}
	}

	public static void add(CusDevice device) {
		if (list == null) {
			list = new ArrayList<CusDevice>();
		}
		list.add(device);
	}

	public static void clearList() {
		list = MyApplication.getInstance().getWidgetDataBase().getCusDevices();
	}
}
